package be.stijn.gdocs.services;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

public class SyncFile {

    private final File file;
    private final File root;

    public SyncFile(File file, File root) {
        this.file = file;
        this.root = root;
    }

    public File getLocalDirectory() {
        return file.getParentFile();
    }

    public String getName() {
        return file.getName();
    }

    public File getFile() {
        return file;
    }

    public File getRootDirectory() {
        return root;
    }

    public boolean isAtRoot() {
        if (file.getParentFile().equals(root)) {
            return true;
        }

        return false;
    }

    /**
     * @return All the parent folders in a ordered list. (dirA/dirB/dirC results in dirA, dirB, dirC)
     */
    public List<String> getParentFolderList() {
        File p = file.getParentFile();
        LinkedList<String> folders = new LinkedList<String>();
        while (!p.getAbsolutePath().equals(root.getAbsolutePath())) {
            folders.addFirst(p.getName());
            p = p.getParentFile();
        }
        return folders;
    }
}
